package com.wbdgj.ui.home;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.internal.LinkedTreeMap;
import com.google.zxing.WriterException;
import com.igexin.sdk.PushManager;
import com.wbdgj.R;
import com.wbdgj.base.BaseActivity;
import com.wbdgj.base.BaseApplication;
import com.wbdgj.http.HttpAdapter;
import com.wbdgj.http.OnResponseListener;
import com.wbdgj.model.ResultObjectModel;
import com.wbdgj.model.ResultUrlModel;
import com.wbdgj.ui.login.LoginActivity;
import com.wbdgj.ui.uitool.ShareBoard;
import com.wbdgj.ui.uitool.ShareBoardlistener;
import com.wbdgj.ui.uitool.SnsPlatform;
import com.wbdgj.utils.QRCodeUtil;
import com.wbdgj.utils.SpKeyUtils;
import com.wbdgj.utils.ToastUtils;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import butterknife.BindView;
import cn.jiguang.share.android.api.JShareInterface;
import cn.jiguang.share.android.api.PlatActionListener;
import cn.jiguang.share.android.api.Platform;
import cn.jiguang.share.android.api.ShareParams;
import cn.jiguang.share.facebook.Facebook;
import cn.jiguang.share.facebook.messenger.FbMessenger;
import cn.jiguang.share.qqmodel.QQ;
import cn.jiguang.share.qqmodel.QZone;
import cn.jiguang.share.twitter.Twitter;
import cn.jiguang.share.wechat.Wechat;
import cn.jiguang.share.wechat.WechatFavorite;
import cn.jiguang.share.wechat.WechatMoments;
import cn.jiguang.share.weibo.SinaWeibo;
import cn.jiguang.share.weibo.SinaWeiboMessage;
import retrofit2.Call;

public class YhqDetailMyHuiActivity extends BaseActivity{

    private Context context = this;
    @BindView(R.id.ewmImg)
    ImageView ewmImg;
    @BindView(R.id.txmImg)
    ImageView txmImg;
    @BindView(R.id.qid)
    TextView qid;

    @BindView(R.id.AMOUNT)
    TextView AMOUNT;
    @BindView(R.id.STATUSS)
    TextView STATUSS;

    private String id;
    private String urlStr;
    private int mAction = Platform.ACTION_SHARE;
    private ShareBoard mShareBoard;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            String toastMsg = (String) msg.obj;
            Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
//            if (progressDialog != null && progressDialog.isShowing()) {
//                progressDialog.dismiss();
//            }
        }
    };

    private String  zt,NAME,MIN_AMOUNT, AMOUNTTxt, ABLE_BRANCH_NAME, BRANCH_NAME, USE_BEG, USE_END, DESCRIBES, BRANCH_ID;

    @Override
    protected int getLayoutResId() {
        return R.layout.ui_wb_yhq_my_detail_hui;
    }

    @Override
    protected void initView() {
        id = getIntent().getStringExtra("id");
        zt = getIntent().getStringExtra("zt");
        AMOUNTTxt = getIntent().getStringExtra("AMOUNT");
        MIN_AMOUNT = getIntent().getStringExtra("MIN_AMOUNT");
        ABLE_BRANCH_NAME = getIntent().getStringExtra("ABLE_BRANCH_NAME");
        NAME = getIntent().getStringExtra("NAME");
        BRANCH_NAME = getIntent().getStringExtra("BRANCH_NAME");
        DESCRIBES = getIntent().getStringExtra("DESCRIBES");
        USE_BEG = getIntent().getStringExtra("USE_BEG");
        USE_END = getIntent().getStringExtra("USE_END");
        BRANCH_ID = getIntent().getStringExtra("BRANCH_ID");
        qid.setText(id);

        if (AMOUNTTxt.equals("0")){
            AMOUNT.setText(NAME);
        }else{
            AMOUNT.setText("优惠金额:"+AMOUNTTxt+"元(消费满"+MIN_AMOUNT+"元可用)");
        }
        STATUSS.setText(zt);

        try {
            // 根据字符串生成二维码图片并显示在界面上，第二个参数为图片的大小（310*310）
            Bitmap bitmapQRCode = QRCodeUtil.createQRCode(id+"",
                    510);
            ewmImg.setImageBitmap(bitmapQRCode);
        } catch (WriterException e) {
            e.printStackTrace();
        }

        txmImg.setImageBitmap(QRCodeUtil.creatBarcode(
                getApplicationContext(), id+"", 100, 30, false));

        findViewById(R.id.qwmdImg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context, WbDetailActivity.class).putExtra("id", BRANCH_ID).putExtra("DISTANCE", ""));
            }
        });

        findViewById(R.id.ABLE_BRANCH_NAME).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context, YhqDetailMyGaginActivity.class).putExtra("ABLE_BRANCH_NAME", ABLE_BRANCH_NAME)
                        .putExtra("BRANCH_NAME", BRANCH_NAME)
                        .putExtra("USE_BEG", USE_BEG)
                        .putExtra("USE_END", USE_END)
                        .putExtra("DESCRIBES", DESCRIBES));

            }
        });

    }

}
